<template>
	<fullScreen v-if="$store.state.admin.admin === false" :model-Value="true" target="#app">
		<div style="display: flex;justify-content: center;align-items: center;">
			<loadingIcon></loadingIcon>
			登录中
			<span v-slow-load>...</span>
		</div>
	</fullScreen>
	<template v-else>
		<!-- 不写$store.state.admin.admin===null的话，会因为路由在/时，导致页面轻微显示异常 -->
		<router-view v-if="$route.meta.needLayout === false || $store.state.admin.admin === null" v-slot="{ Component }">
			<keep-alive :exclude="$store.state.tagsView.exclude"><component :is="Component" /></keep-alive>
		</router-view>
		<layout v-else></layout>
	</template>
</template>

<script>
import layout from '@/layout/mainLayout.vue';
import fullScreen from '@/component/common/FullScreen.vue';
import loadingIcon from '@/component/common/loadingIcon.vue';
export default {
	components: {
		layout,
		fullScreen,
		loadingIcon
	},
	created() {
		//进行登录
		setTimeout(() => {
			try {
				let admin = window.localStorage.admin;
				admin = JSON.parse(admin);
				if (admin) {
					this.$store.commit('admin/login', admin);
				} else {
					//没登录，就跳转登录页面
					this.$router.push('/AdminLogin');
					this.$store.commit('admin/login', null);
				}
			} catch (e) {
				this.$router.push('/AdminLogin');
				this.$store.commit('admin/login', null);
			}
		}, 150);
	}
};
</script>

<style lang="scss">
* {
	margin: 0;
	padding: 0;
	outline: none;
	text-decoration: none;
	list-style: none;
	font-family: "Microsoft YaHei";
}
html,
body,
#app {
	width: 100%;
	height: 100%;
	overflow: hidden;
}
#app {
	display: flex;
	flex-direction: column;
}
</style>
